#!/usr/bin/python
from Classification import NewData
from Classification import Die
import time
import os

class Document(NewData):
    def __init__(self):
        NewData.__init__(self)
        self.this_type =Die['document'] 
    def look(self):
        temp_list = self.get_type(self.this_type)
        print self.this_type
        for item in temp_list:
            print "\t%s" %item[2]
    def add(self,values):
        pro_type = [self.this_type,values]
        self.insert_type(pro_type)
    def delet(self,values): # this function is not finished!!
        pro_type = [self.this_type,values]
        #self.cu.execute("delet values from file_type")
        
class Picture(Document):
    def __init__(self):
        Document.__init__(self)
        self.this_type =  Die['picture']

class Music(Document):
    def __init__(self):
        Document.__init__(self)
        self.this_type = Die['music']
class Movie(Document):
    def __init__(self):
        Document.__init__(self)
        self.this_type = Die['movie']

class Life_process:
    
    def __init__(self):
        print "Initializeing....."
        time.sleep(0.3)
        print "Check ....",
        try:
            self.document = Document()
            self.music = Music()
            self.picture = Picture()
            self.movie = Movie()
            print "ok"
        except TypeError:
            exit(1)
        self.Direction = ""
        self.menue()
    def menue(self):
        os.system("clear")
        print "\t\t\tLook or Add\n"
        print "\tpress 'l' to look | 'a' to Add\n |'q' to exit"
        self.Direction = raw_input(">>>  ")
        if (self.Direction == 'l' ):
            self.Look()
        elif (self.Direction == 'a'):
            self.Add()
        elif (self.Direction == 'q'):
            self.exit()
        else : 
            self.menue()
    def Look(self):
        self.document.look()
        self.picture.look()
        self.movie.look()
        self.music.look()
        self.Direction = raw_input("\nThen add('a') exit('q')\n>>>  ")
        if (self.Direction == 'a'):
            self.Add()
        elif(self.Direction == 'q'):
            self.exit()
        else:
            self.Look()
    def Add(self):
        type_direction = None
        print "Choise type to add , where file to add ?"
        for item in Die.keys():
            print item ,
        type_direction = raw_input(">> ")
        for item in Die.keys():
            if item == type_direction:
                print "check ...",
                time.sleep(0.2)
                print "ok"
                self.Add_2(type_direction)
            
        print "No such file  try again('r') or exit('q')?"
        self.Direction = raw_input(">>  ")
        if self.Direction == 'q':
            self.exit()
        elif (self.Direciton == 'r'):
            self.Add()
    def Add_2(self,type):
        while self.Direction != 'm':
            self.Direction = raw_input(">> 'm' to return\n ")
            if (self.Direction == 'm'):
                self.Add()
            else:
                if type == 'picture':
                    data_type = raw_input("pic : ")
                    self.picture.add(data_type)
                elif type == 'movie':
                    data_type = raw_input("mov :")
                    self.movie.add(data_type)
                elif type == 'document':
                    data_type = raw_input("doc : ")
                    self.document.add(data_type)
                elif type == 'music':
                    data_type = raw_input("mic : ")
                    self.music.add(data_type)
    def exit(self):
        print "Now is : %s" % time.ctime()
        print "Good bye qingluan"
        time.sleep(0.5)
        exit(0)
if __name__ == "__main__":
    process =  Life_process()
